package com.example.stock.business.monitor.logic;

import com.example.stock.excel.Monitor;
import com.example.stock.model.WeekDetail;
import com.example.stock.service.WeekDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 周价格监控
 */
@Component
public class WeekCloseMonitor implements Trigger{

    @Autowired
    WeekDataService weekDataService;

    @Override
    public boolean trigger(Monitor monitor) {
        WeekDetail currentWeekDetail = weekDataService.getCurrentWeekDetail(monitor.getStock());
        if (currentWeekDetail == null) {
            return false;
        }

        return switch (monitor.getCategory()) {
            case "15UP" -> currentWeekDetail.getW15DisPct() >= 0;
            case "15DOWN" -> currentWeekDetail.getW15DisPct() < 0;
            case "20UP" -> currentWeekDetail.getGb20wPct() >= 0;  // 突破20周线
            case "20DOWN" -> currentWeekDetail.getGb20wPct() < 0;  // 跌破20周线
            case "30UP" -> currentWeekDetail.getGb30wPct() >= 0;
            case "30DOWN" -> currentWeekDetail.getGb30wPct() < 0;
            case "60UP" -> currentWeekDetail.getDisPct() >= 0;
            case "60DOWN" -> currentWeekDetail.getDisPct() < 0;
            default -> false;
        };
    }
}
